import { $get } from '@js/authRequest'

// 获取请求项配置
export async function getClaimItemConfigRequest () {
  const res = await $get('/api/xapc/claimitemconfig')
  if (res.status !== 1) {
    throw new Error(res.message)
  }
  return formatCaseTypeTree(res.data)
}

// 格式化案件类型树对象
function formatCaseTypeTree (list, titles = []) {
  return list.map(li => {
    li.titles = [...titles, li.title]
    if (li.children && li.children.length) {
      li.children = formatCaseTypeTree(li.children, li.titles)
    } else {
      delete li.children
    }
    return li
  })
}
